form_ok=true;
window.onload=function(){
	before_submit()
	yzm_value=yzm("yzm");
	var form=document.forms[0];
	var form_submit_ok=document.getElementById("form_ok");
	addEvent(form,"submit",function(event){
		preventDefault(event);
		if(form_ok){
			var username=form.elements["username"].value;
			var password=form.elements["password"].value;
			var email=form.elements["email"].value;
			get_ajax("../back_stage/login_stage.php",{register:true,username:username,password:password,email:email},function(text){
				if(text=="ok"){
					form_submit_ok.innerHTML="注册成功";
					window.open("login.php","_self");
				}else{
					form_submit_ok.innerHTML=text;
				}
			},false);
		}else{
			form_submit_ok.innerHTML="填写信息有错误";
		}
	});
}
//给表单绑定验证函数
function before_submit(){
	var reg=/^(?:\w+\.?)*\w@(?:\w+\.?)*\w$/;
	form_check("email",reg,"邮箱格式错误");
	reg=/[^<>\'\"\ \　]/;
	form_check("username",reg,"用户名不能包含特殊字符");
	form_check("password","mm","密码不能小于6位");
	form_check("password_ok","mm_ok","前后密码不一致");
	form_check("yanzhengma","yzm","验证码错误");
}
//验证表单项
function form_check(name,reg,info){
	var elem=document.getElementById(name);
	addEvent(elem,"blur",function(){
		var str=elem.value;
		if(reg=="mm"){//如果是密码
			if(str.length<6){
				var jmp=new jump(elem);
				jmp.h_jump();
				elem.style.cssText="background-color:#f69d9d;border:1px solid #F9F";
				elem.nextSibling.innerHTML=info;
				form_ok=false;
			}else{
				elem.nextSibling.innerHTML="正确";
				form_ok=true;
				elem.style.cssText="";
			}
		}else if(reg=="yzm"){
			var yzm=document.getElementById("yanzhengma");
			if(yzm.value!=yzm_value){
				var jmp=new jump(elem);
				jmp.h_jump();
				elem.style.cssText="background-color:#f69d9d;border:1px solid #F9F";
				form_ok=false;
			}else{
				form_ok=true;
				elem.style.cssText="";
			}
		}else if(reg=="mm_ok"){//如果是密码确认
			var password=document.getElementById("password").value;
			if(str!=password){
				var jmp=new jump(elem);
				jmp.h_jump();
				elem.style.cssText="background-color:#f69d9d;border:1px solid #F9F";
				elem.nextSibling.innerHTML=info;
				form_ok=false;
			}else{
				elem.nextSibling.innerHTML="正确";
				form_ok=true;
				elem.style.cssText="";
			}
		}else{
			if(!reg.test(str)){
				var jmp=new jump(elem);
				jmp.h_jump();
				elem.style.cssText="background-color:#f69d9d;border:1px solid #F9F";
				elem.nextSibling.innerHTML=info;
				form_ok=false;
			}else{
				elem.nextSibling.innerHTML="正确";
				form_ok=true;
				elem.style.cssText="";
			}
		}
	});
}
